package revise.Array;

import java.util.Arrays;

//                                 对数组的各种操作
public class Test5 {

    public static int find(int[] arr,int target){
        int i = 0;
        for (i = 0; i < arr.length; i++){
            if(arr[i] == target){
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        //六、
        //1.数组转化为字符串
        // Arrays.toString()
        int[] arr1 = {1, 2, 3};
        System.out.println(Arrays.toString(arr1));
        //2.数组拷贝
        //使用Arrays.copyOf(arr,3);
        int[] arr2 = {1, 3, 5, 7, 9};
        int[] arr3 = Arrays.copyOf(arr2,3);
        System.out.println(Arrays.toString(arr3));
        //使用Arrays.copyOfRange(arr,2,4)
        int[] arr4 = Arrays.copyOfRange(arr2,2,4);//左闭右开[2,4)
        System.out.println(Arrays.toString(arr4));
        //3.查找指定数组中的元素
        //顺序查找
        int[] arr5 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int index = find(arr5,7);
        System.out.println(index);
    }
}
